<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb1">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getalllist()"></right-toolbar>
    </el-row>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="会员单位入会申请" name="first">
        <el-row :gutter="20">
          <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
            <!--单位会员数据-->
            <pane size="84">
              <el-col>
                <el-table v-loading="loading" :data="unitList" @selection-change="">
                  <el-table-column type="selection" width="50" align="center" />
                  <el-table-column label="LOGO" align="center" key="member_logo" prop="member_logo" />
                  <el-table-column label="会员单位名称" align="center" key="member_unit_name" prop="member_unit_name"
                    :show-overflow-tooltip="true" />
                  <el-table-column label="会员单位等级" align="center" key="member_grade" prop="member_grade"
                    :show-overflow-tooltip="true" />
                  <el-table-column label="联系人" align="center" key="contact" prop="contact"
                    :show-overflow-tooltip="true" />
                  <el-table-column label="联系电话" align="center" key="phone" prop="phone" width="120" />
                  <el-table-column label="职位" align="center" key="position" prop="position" />
                  <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
                    <template slot-scope="scope" v-if="scope.row.userId !== 1">
                      <el-button size="mini" type="text" icon="el-icon-edit"
                        v-hasPermi="['system:user:edit']">修改</el-button>
                      <el-button size="mini" type="text" icon="el-icon-edit"
                        v-hasPermi="['system:user:edit']">详情</el-button>
                      <el-button size="mini" type="text" icon="el-icon-delete"
                        v-hasPermi="['system:user:remove']">注销</el-button>
                    </template>
                  </el-table-column>
                </el-table>

                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @pagination="" />
              </el-col>
            </pane>
          </splitpanes>
        </el-row>
      </el-tab-pane>
      <el-tab-pane label="下辖成员入会申请" name="second">
        <el-row :gutter="20">
          <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
            <!--单位会员数据-->
            <pane size="84">
              <el-col>
                <el-table v-loading="loadingss" :data="memberList" @selection-change="">
                  <el-table-column type="selection" width="50" align="center" />
                  <el-table-column label="头像" align="center" key="avatar" prop="avatar" width="120" />
                  <el-table-column label="用户名" align="center" key="apply_name" prop="apply_name" />
                  <el-table-column label="身份" align="center" key="type" prop="type" :show-overflow-tooltip="true" >
                    <template slot-scope="scope">
                      <span v-if="scope.row.type == 1">运动员</span>
                      <span v-if="scope.row.type == 2">教练员</span>
                      <span v-if="scope.row.type == 3">裁判员</span>
                      <span v-if="scope.row.type == 4">业余运动员</span>
                    </template>
                    </el-table-column>
                  <el-table-column label="手机号" align="center" key="phone" prop="phone" :show-overflow-tooltip="true" />
                  <el-table-column label="审批状态" align="center" key="status" prop="status" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                      <span v-if="scope.row.status == 1">待审核</span>
                      <span v-if="scope.row.status == 2">申请成功</span>
                      <span v-if="scope.row.status == 3">申请失败</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="申请时间" align="center" key="create_time" prop="create_time" />dentity_card" />
                  <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button  size="mini" type="text" icon="el-icon-edit"  @click="handleUpdate(scope.row)"
                        v-hasPermi="['system:user:edit']" v-if="scope.row.status == 1">审批</el-button>
                        <span v-if="scope.row.status !== 1"> 审核完成</span>
                    </template>
                  </el-table-column>
                </el-table>

                <pagination v-show="totals > 0" :total="totals" :page.sync="query.pageNum" :limit.sync="query.pageSize"
                  @pagination="" />
              </el-col>
            </pane>
          </splitpanes>
        </el-row>
      </el-tab-pane>
    </el-tabs>
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="审核" prop="name">
          <el-button type="primary" @click="changeApprovePass">通过</el-button>
          <el-button type="danger" @click="changeApproveOverPass">拒绝</el-button>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { ApiGetlistMemberApplys, ApiGetlistUnitApplys, ApiApprove } from "@/api/common/common";
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
export default {
  dicts: [],
  components: { Splitpanes, Pane },
  data() {
    return {
      open: false,
      title: "",
      activeName: 'first',
      // 单位入会遮罩层
      loading: false,
      // 下辖成员入会遮罩层
      loadingss: false,
      // 单位入会表格数据
      unitList: null,
      // 下辖会员入会表格数据
      memberList: null,
      // 会员单位入会总条数
      total: 0,
      // 下辖成员入会总条数
      totals: 0,
      status: 0,
      // 会员单位入会查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 下辖成员入会查询参数
      query: {
        pageNum: 1,
        pageSize: 10,
      },
      form: {},
    };
  },
  created() {
    this.getMemberApplyList();
    this.getUnitApplyList();
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
    },
    getalllist(){
      this.getMemberApplyList();
      this.getUnitApplyList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        this.form.status = this.status;
        ApiApprove(this.form).then(response => {
          this.open = false;
          this.getList();
        });
      });
    },
    changeApprovePass() {
      this.status = 2;
    },
    changeApproveOverPass() {
      this.status = 3;
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    /** 查询团队入会申请列表 */
    getUnitApplyList() {
      ApiGetlistUnitApplys().then((res) => {
        this.unitList = res.rows;
      })
    },
    /** 查询会员入会申请列表 */
    getMemberApplyList() {
      ApiGetlistMemberApplys().then((res) => {
        this.memberList = res.rows;
      })
    },
    handleUpdate(row) {
      this.title = "审批会员入会申请";
      this.open = true;
      this.form = row;
    }
  }
};
</script>
